1 from .other import dict_to_csv_line, dict_from_entries
2
3 columns = (
4     
'id',
5     
'date',
6     
'total_price',
7     
'num_products',
8     
'product_id',
9     
'employee_id'
10 )
11
12
13 def get_sales():
14     sales = []
15     file = open(
'sales.csv')
16     
for line in file:
17         id, date, total_price, num_products, product_id, employee_id = line.split(
18             
',')
19
20         sales.append(dict_from_entries(columns, (
21             
int(id),
22             date,
23             
float(total_price),
24             
int(num_products),
25             
int(product_id),
26             
int(employee_id.rstrip()),
27         )))
28
29     file.close()
30     
return tuple(sales)
31
32
33 def add_sale(sale):
34     file = open(
'sales.csv', 'a')
35     line = dict_to_csv_line(sale, columns)
36
37     file.write(line)
38     file.close()


Gõ tìm kiếm nhanh...